#include<iostream>
using namespace std;
void SelectSort(int *a,int len)
{
    int left=0,right=len-1;
    while(left<right)
    {    
        int min=left;
        int max=right;
        for(int j=left;j<=right;j++)
        {
            if(a[min]>a[j])
            {
                min=j;
            }
            else if(a[max]<a[j])max=j;   
        }
        swap(a[min],a[left]);
        if(max==left)
        {
            max=min;
        }
        swap(a[max],a[right]);
        left++,right--;
    }
}
int main()
{
    int a[]={1,5,6,7,41,2,3,6};
 
    SelectSort(a,sizeof(a)/sizeof(a[0]));
    for(int i=0;i<8;i++)
    {
        cout<<a[i]<<" ";
    }
}